(function(angular) {
	"use strict";
	angular.module("fs.waf").factory("settleInitDchargeService", settleInitDchargeService);
	settleInitDchargeService.$inject = [ "$filter", "txnService" ];
	function settleInitDchargeService($filter, txnService) {

		function getCompanyCodeByAlloc(settlement, allocCode) {
			var custCode = "", encode = $filter("encode");
			if (allocCode == "CUSTOMER")
				custCode = encode(settlement.dcharge.custCode);
			else if (allocCode == "OBLIGOR")
				custCode = encode(settlement.dcharge.obligorCode);
			else
				custCode = encode(settlement.dcharge.custCode);

			return custCode;
		}
		function getCcy(settlement) {
			return settlement.dcharge.refCcy;
		}
		function getTxnAmount(settlement) {
			return settlement.dcharge.refAmt;
		}
		function getAssetId(settlement) {
			return settlement.dcharge.assetId;
		}
		function getProdCodeAndType(settlement) {
			var prodType = settlement.dcharge.prodType;
			return {
				prodCode : "",
				prodType : prodType
			};
		}
		function getDeductIntAndFeeFlag(settlement) {
			return {
				deductIntFlag : "Y",
				deductFeeFlag : "Y"
			};
		}
		function getGeneralConfig(layoutConfig) {
			var generalConfig = angular.copy(layoutConfig.formConfigs.dcharge);
			return generalConfig;
		}
		
		function getGeneralModel(settlement) {
			return settlement.dcharge;
		}
		
		function processDynaparmConfig(loyout){
			angular.forEach(loyout.formConfigs.dcharge.gridConfigs, function(gridConfig){
				if(gridConfig.model.indexOf("dynamicParams.") != -1){
					gridConfig.model = "dcharge." + gridConfig.model;
				}
			});
		}

		function getBackMessage() {
			return "title.infobar.dchg.update";
		}

		function getLayout(settlement, packageSuffix) {
			return txnService.getLayout("settlement", packageSuffix, false, "DIRECTCHARGE", settlement.dcharge.prodType, undefined);
		}
		
		return {
			getCcy : getCcy,
			getTxnAmount : getTxnAmount,
			getAssetId : getAssetId,
			getCompanyCodeByAlloc : getCompanyCodeByAlloc,
			getDeductIntAndFeeFlag : getDeductIntAndFeeFlag,
			getProdCodeAndType : getProdCodeAndType,
			getGeneralConfig : getGeneralConfig,
			getBackMessage : getBackMessage,
			getLayout : getLayout,
			getGeneralModel : getGeneralModel,
			processDynaparmConfig : processDynaparmConfig
		};
	}
})(angular);
